package com.woniuxy.location.controller;

import com.woniuxy.commons.entity.DisabledAddress;
import com.woniuxy.commons.log.annotation.RequireLog;
import com.woniuxy.commons.util.ResponseResult;
import com.woniuxy.commons.util.ResultStatus;
import com.woniuxy.location.service.AddressService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@Slf4j
@RequestMapping("/address")
public class AddressController {
    @Resource
    AddressService addressService;
    // 查询地址
    @RequireLog(module = "地址",type = "查询")
    @GetMapping("/find/{did}")
    public ResponseResult findAddressByDisabledId(@PathVariable("did") int did){
        List<DisabledAddress> addressList = addressService.findAddressByDisabledId(did);
        ResponseResult responseResult = new ResponseResult();
        responseResult.setCode(200);
        responseResult.setMsg("查询地址成功");
        responseResult.setData(addressList);
        responseResult.setStatus(ResultStatus.SUCCESS);
        return responseResult;
    }
    // 添加地址
    @RequireLog(module = "地址",type = "添加")
    @PostMapping("/add")
    public ResponseResult addAddress(@RequestBody DisabledAddress address){
        ResponseResult responseResult = new ResponseResult();
        addressService.addAddress(address);
            responseResult.setCode(200);
            responseResult.setMsg("添加地址成功");
            responseResult.setStatus(ResultStatus.SUCCESS);
            return responseResult;
    }
    @RequireLog(module = "地址",type = "删除")
    @DeleteMapping("/del/{id}")
    public ResponseResult delAddress(@PathVariable("id") int id){
        ResponseResult responseResult = new ResponseResult();
        addressService.delAddressById(id);
        responseResult.setCode(200);
        responseResult.setMsg("删除地址成功");
        responseResult.setStatus(ResultStatus.SUCCESS);
        return responseResult;
    }
    @RequireLog(module = "地址",type = "修改")
    @PutMapping("/update")
    public ResponseResult delAddress(@RequestBody DisabledAddress address){
        ResponseResult responseResult = new ResponseResult();
        addressService.updateAddress(address);
        responseResult.setCode(200);
        responseResult.setMsg("修改地址成功");
        responseResult.setStatus(ResultStatus.SUCCESS);
        return responseResult;
    }
}
